package com.jbp.controller;

import com.jbp.model.Skill;
import com.jbp.model.SkillOrderComment;
import com.jbp.service.SkillOrderCommentService;
import com.jbp.utils.PageUtils;
import com.jbp.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

/**
 * 订单评论(SkillOrderComment)表控制层
 * @author cc
 * @since 2020-11-28 17:49:31
 */
@Api(tags ="APP接口--SkillOrderComment" )
@RestController
@RequestMapping("rest/skillOrderComment")
public class SkillOrderCommentController {
    @Autowired
    private SkillOrderCommentService skillOrderCommentService;

    /** 列表 */
    @ApiOperation(value="列表")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功",response = SkillOrderComment.class),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        if (params.get("skillUserId")==null) {
            return R.error("参数错误");
        }
        PageUtils page = skillOrderCommentService.queryPage(params);
        return R.ok(page);
    }

    @ApiOperation(value="我的评论列表")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功",response = SkillOrderComment.class),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @GetMapping("/myComments")
    public R myComments(@RequestParam Map<String, Object> params, @RequestAttribute("userId") Integer userId){
        PageUtils page = skillOrderCommentService.myComments(params, userId);
        return R.ok(page);
    }

    /** 保存 */
    @PostMapping("/save")
    public R save(@RequestBody SkillOrderComment skillOrderComment, @RequestAttribute("userId") Integer userId){
        if (skillOrderComment.getSkillOrderId()==null) {
            return R.error("订单号不能为空");
        }
        if (skillOrderComment.getScore()==null) {
            return R.error("请评分");
        }
        skillOrderCommentService.save(skillOrderComment, userId);
        return R.ok();
    }

    @ApiOperation(value="我对某个订单的评论")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功",response = SkillOrderComment.class),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @GetMapping("/myComment")
    public R myComment(@RequestParam Integer skillOrderId, @RequestAttribute("userId") Integer userId){
        return R.ok(skillOrderCommentService.myComment(skillOrderId, userId));
    }
}